#include "stm32f10x.h"
#include "stm32f10x_it.h"
#include "rtthread.h"

#define TASK_THREAD_STACK_SIZE 1024

#ifndef RT_USING_HEAP
/* if there is not enable heap, we should use static thread and stack. */
ALIGN(8)
static rt_uint8_t led_thread1_stack[TASK_THREAD_STACK_SIZE];
struct rt_thread led_thread1;
#endif

void led_thread1_entry(void *parameter);


void bsp_init(void)
{
    GPIO_InitTypeDef GPIO_InitStructure;

    RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOC,ENABLE);

    GPIO_InitStructure.GPIO_Pin = GPIO_Pin_13;
    GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP;
    GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
    GPIO_Init(GPIOC,&GPIO_InitStructure);
    
    GPIO_WriteBit(GPIOC,GPIO_Pin_13, Bit_SET);
    GPIO_WriteBit(GPIOC,GPIO_Pin_13, Bit_RESET);
}


void task_creat(void)
{
    rt_enter_critical();
    
    rt_thread_init(&led_thread1, "led_thread1", led_thread1_entry, RT_NULL,led_thread1_stack, sizeof(led_thread1_stack), 1, 20);
    rt_thread_startup(&led_thread1);
    
    rt_exit_critical();
}

int main(void)
{
    bsp_init();
    task_creat();
    
    while (1)
    {
        rt_thread_mdelay(500);
    }
}

void led_thread1_entry(void *parameter)
{
    while (1)
    {
        GPIO_WriteBit(GPIOC,GPIO_Pin_13, Bit_RESET);
        rt_thread_mdelay(100);
        GPIO_WriteBit(GPIOC,GPIO_Pin_13, Bit_SET);
        rt_thread_mdelay(100);
    }
}



